<?php
require_once('db_connect.php');
?>

<html>
<head>
<title>Search for your residence, ol' chap.</title>
<link rel=stylesheet href="style.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function get_result() {
	var xmlhttp;
	xmlhttp=new XMLHttpRequest();
	request_str="";
	request_str += "area_min=" + document.getElementById("area_min").value;
	request_str += "&area_max=" + document.getElementById("area_max").value;
	request_str += "&room_min=" + document.getElementById("room_min").value;
	request_str += "&room_max=" + document.getElementById("room_max").value;
	request_str += "&price_min=" + document.getElementById("price_min").value;
	request_str += "&price_max=" + document.getElementById("price_max").value;
	request_str += "&rent_min=" + document.getElementById("rent_min").value;
	request_str += "&rent_max=" + document.getElementById("rent_max").value;
	
	type = document.getElementById("type");
	j = 0;
	for(i = 0; i < type.childNodes.length; i++){
		if(type.childNodes[i].checked){
			request_str += "&type" + j + "=";
			request_str += type.childNodes[i].value;
			j++;
		} 
	}

        lan = document.getElementById("lan");
        j = 0;
        for(i = 0; i < lan.childNodes.length; i++){
                if(lan.childNodes[i].checked){
                        request_str += "&lan" + j + "=";
                        request_str += lan.childNodes[i].value;
                        j++;
                }
        }  

	xmlhttp.open("GET", "result.php?" + request_str, false);
	xmlhttp.send();
	
	document.getElementById("result").innerHTML = xmlhttp.responseText; 
}
</script>
 
</head>
<body>
<h1>Search for your residence, ol' chap.</h1>
<div>
<div class="sbox">
<h2>Province</h2>
<?php
$i = 0;
$result = pg_query('SELECT DISTINCT lan FROM bostader');
echo '<form id="lan">';
while($row = pg_fetch_assoc($result)){
	echo '<input type="checkbox" id="lan'.$i.'" value="'.$row['lan'].'" />'.$row['lan'].'<br />';
$i++;
} 
echo '</form>';
?>
</div>

<div class="sbox">
<h2>Type of accomodation</h2>
<?php  
$i = 0;
$result = pg_query('SELECT DISTINCT objekttyp FROM bostader');
echo '<form id="type">';
while($row = pg_fetch_assoc($result)){
        echo '<input type="checkbox" id="type'.$i.'" value="'.$row['objekttyp'].'" />'.$row['objekttyp'].'<br />';
$i++;
}
echo '</form>';
?>
</div>

<div class="sbox">
<h2>Refine your search</h2>
<p class="trolol">From - To</p>
<select id="area_min">
	<option value="0">Area</option>
        <option value="0">0</option>
        <option value="25">25</option>
        <option value="50">50</option>
        <option value="75">75</option>
        <option value="100">100</option>
        <option value="125">125</option>
        <option value="150">150</option>
        <option value="200">200</option>
        <option value="300">300</option>
        <option value="301">&gt;300</option>
</select>

<select id="area_max">   
        <option value="max">Area</option>
        <option value="0">0</option>          
        <option value="25">25</option>        
        <option value="50">50</option>
        <option value="75">75</option>
        <option value="100">100</option>
        <option value="125">125</option>
        <option value="150">150</option>
        <option value="200">200</option>
        <option value="300">300</option>
        <option value="max">&gt;300</option>
</select>
<br />
<select id="room_min">   
        <option value="1">Rooms</option>
        <option value="1">1</option>          
        <option value="2">2</option>        
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
        <option value="10">&gt;9</option>
</select>

<select id="room_max">
        <option value="max">Rooms</option>
        <option value="1">1</option>
        <option value="2">2</option>    
        <option value="3">3</option>  
        <option value="4">4</option>  
        <option value="5">5</option>    
        <option value="6">6</option>    
        <option value="7">7</option>      
        <option value="8">8</option>    
        <option value="9">9</option>    
        <option value="max">&gt;9</option>    
</select>
<br />
<select id="price_min">
        <option value="0">Price</option>
        <option value="0">0</option>
        <option value="100000">100000</option>
        <option value="300000">300000</option>
        <option value="500000">500000</option>
        <option value="1000000">1000000</option>
        <option value="1500000">1500000</option>
        <option value="2000000">2000000</option>
        <option value="3000000">3000000</option>
        <option value="5000000">5000000</option>
        <option value="5000001">&gt;5000000</option>
</select>

<select id="price_max">
        <option value="max">Price</option>
        <option value="0">0</option>
        <option value="100000">100000</option>
        <option value="300000">300000</option>
        <option value="500000">500000</option> 
        <option value="1000000">1000000</option>
        <option value="1500000">1500000</option>
        <option value="2000000">2000000</option>
        <option value="3000000">3000000</option>
        <option value="5000000">5000000</option>
        <option value="max">&gt;5000000</option>
</select>
<br />
<select id="rent_min">
        <option value="0">Rent/Fee</option>
        <option value="0">0</option>
        <option value="1000">1000</option>
        <option value="2000">2000</option>
        <option value="3000">3000</option>  
        <option value="4000">4000</option>
        <option value="5000">5000</option>
        <option value="6000">6000</option>
        <option value="7000">7000</option>
        <option value="8000">8000</option>
        <option value="8001">&gt;8000</option>
</select>

<select id="rent_max"> 
        <option value="max">Rent/Fee</option> 
        <option value="0">0</option>
        <option value="1000">1000</option>    
        <option value="2000">2000</option>    
        <option value="3000">3000</option>    
        <option value="4000">4000</option>      
        <option value="5000">5000</option>      
        <option value="6000">6000</option>      
        <option value="7000">7000</option>      
        <option value="8000">8000</option>      
        <option value="max">&gt;8000</option>      
</select>


</div>

<input type="submit" value="Search" onClick="get_result()" />

</div>

<div id="result">

</div>

</body>
</html>
